package com.itheima.controller;

import com.itheima.domain.Department;
import com.itheima.domain.Patient;
import com.itheima.service.DepartmentService;
import com.itheima.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/*
 *Author:TH
 *Dete:2019/10/1420:28
 */
@Controller
@RequestMapping("/depart")
public class PatientController {

    @Autowired
    private PatientService patientService;
    @RequestMapping("/findAll")
    @ResponseBody
    public String findAll(Model model){
        List<Patient> patientList = patientService.findAll();
        model.addAttribute("patientList",patientList);
        return "patients-list";
    }

    @RequestMapping("save")
    public String save(Patient patient){
        patientService.save(patient);
        return "findAll";
    }

    @RequestMapping("findById")
    public String findById(String id,Model model){
        Patient patient = patientService.findById(id);
        model.addAttribute("patient",patient);
        return "subscribe-form-update";
    }

    @RequestMapping("change")
    public String change(Patient patient,Model model){
         patientService.change(patient);
        model.addAttribute("patient",patient);
        return "subscribe-form-update";
    }
}
